﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EntityFramework
{
    public class CompaniesBO : BaseBO
    {
        public static List<Company> GetCompaniesByZoneId(int zoneId)
        {
            using (var _db = new DbWebsite())
            {
                return _db.StoredProcedures.GetCompaniesByZoneId(zoneId);
            }
        }

        public static List<Company> GetCompaniesByZoneIds(int zoneid)
        {
            List<Company> lst = null;
            using (var _db = new DbWebsite())
            {
                lst = _db.StoredProcedures.GetCompaniesByZoneIds(zoneid);
            }
            if (lst.Any())
            {
                foreach (var item in lst)
                {
                    item.Url += "c/"+  zoneid + "/" + item.CompanyID +  "/"+ BO.Utils.BuildLinkUrlNice(item.NameCp);
                }
            }
            return lst;
        }

        public static Company GetCompaniesByID(int companyID)
        {
            using (var _db = new DbWebsite())
            {
                return _db.StoredProcedures.GetCompaniesByID(companyID);
            }
        }

        public static string GetCompaniesNameByZoneId(int zoneId)
        {
            string name = string.Empty;
            List<Company> lst = GetCompaniesByZoneId(zoneId);
            if (lst.Any())
            {
                foreach (var item in lst)
                {
                    name += item.NameCp + ",";
                }
            }
            return name;
        }

        
    }
}
